import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/public_baseState.dart';
import 'package:honeypotflutter/public/views/public_scanf.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:scan/scan.dart';

class MGScanf extends StatefulWidget {
  final String title;
  final Function(String value)? scanfResult;
  const MGScanf({super.key, this.title = "请对准柜机二维码扫描", this.scanfResult});

  @override
  State<MGScanf> createState() => _MGScanfState();
}

class _MGScanfState extends HLBaseState<MGScanf> {
  ScanController? controller = ScanController();

  @override
  void didPopNext() {
    controller?.resume();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          HLScanf(
            controller: controller,
            lineColor: MGColors.themeColor,
            onCapture: widget.scanfResult,
          ),
          Container(
            width: double.infinity,
            margin: EdgeInsets.only(bottom: 50),
            child: Column(
              children: [
                Text(
                  widget.title,
                  style: TextStyle(
                    color: MGColors.whileColor,
                    fontSize: MGFont.titleFont4,
                  ),
                ),
                SizedBox(height: 20),
                TextButton(
                    onPressed: () {
                      Get.back();
                    },
                    child: Text(
                      "关闭",
                      style: TextStyle(
                        color: MGColors.whileColor,
                        fontSize: MGFont.titleFont4,
                      ),
                    ))
              ],
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
            ),
          )
        ],
      ),
    );
  }

  @override
  void dispose() {
    controller = null;
    super.dispose();
  }
}
